<template>
  <div id="payOftenEdit">
    <div class="title"></div>
    <div class="content">
      <div class="pay_often_edit" v-if="oInitEditPaySchedule">
        <el-row class="pay_often_edit_content">
          <el-col :span="12" class="left_content">
            <div class="title">What's {{oInitEditPaySchedule.personName}}'s pay schedule?</div>
            <div class="question">
              How often do you pay {{oInitEditPaySchedule.personName}}?
            </div>
            <div class="answer">
              <el-select style="width:160px" v-model="payOftenEditModel.howOftenId">
                <el-option v-for="(item,key) in oInitEditPaySchedule.howOften" :key="key"  :label="item.showName" :value="item.value"></el-option>
              </el-select>
            </div>
            <div class="question">When's the next payday?</div>
            <div class="answer">
              <el-date-picker type="date"  format="MM/dd/yyyy" v-model="payOftenEditModel.nextPayDay" placeholder="select payday" style="width: 160px;" @change="function(value){payOftenEditModel.nextPayDay = value}"></el-date-picker>
            </div>
            <div class="question">When's the last day of work (pay period) for that payday?</div>
            <div class="answer">
              <el-date-picker type="date" format="MM/dd/yyyy" v-model="payOftenEditModel.lastWorkDay" placeholder="select birth date" style="width: 160px;" @change="function(value){payOftenEditModel.lastWorkDay = value}"></el-date-picker>
            </div>
            <div class="question">What do you want to name this pay schedule?</div>
            <div class="answer"><el-input v-model="payOftenEditModel.payScheduleName" placeholder="" style="width: 160px;"></el-input></div>
            <div class="pay_often_edit_btn_group">
              <el-button :disabled="!isCanSubmit" type="primary" @click="submit">Done</el-button>
              <el-button @click="$router.back()">Cancel</el-button>
            </div>
          </el-col>
          <el-col :span="11" :offset="1" class="right_content">
            <div class="pay_date_list">
              <div class="title">Next four pay periods (based on dates you entered)</div>
              <div class="pay_date_list_content" v-if="payPeriod">
                <el-row class="pay_date_item title">
                  <el-col :span="13" :offset="1">PAY PERIODS</el-col>
                  <el-col :span="9" :offset="1">PAYDAY</el-col>
                </el-row>
                <el-row class="pay_date_item" v-for="(item,key) in payPeriod" :key="key" >
                  <el-col :span="13" :offset="1">{{item.startDate}}—{{item.endDate}}</el-col>
                  <el-col :span="9" :offset="1">{{item.payDay}}</el-col>
                </el-row>
              </div>
              <div class="bottom_circle">
                <span v-for="key in 11"  :key="key"  class="circle_item" :style="{left:50*key +'px',bottom:Math.random()*(-40)-11+'px'}"></span>
              </div>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
  </div>
  <!--<div class="loading_content" v-else v-loading="true"  element-loading-text="loading"></div>-->
</template>

<script>
  export default {
    components:{
    },
    data:function(){
      return{
        //数据Model
        payOftenEditModel:{
          howOftenId:"",
          nextPayDay:"",
          lastWorkDay:"",
          payScheduleName:""
        },
      }
    },
    created:function(){
      this.$store.dispatch('initEditPaySchedule',{personId:this.getPersonId()})
    },
    activated:function(){
      //this.$store.dispatch('initEditPaySchedule',{personId:this.getPersonId()})
    },
    deactivated:function () {
      this.clearData();
    },
    computed:{
      oInitEditPaySchedule(){
          return this.$store.getters.oInitEditPaySchedule;
      },
      listPayPeriods(){
        if(typeof (this.payOftenEditModel.lastWorkDay)!='string'||typeof this.payOftenEditModel.nextPayDay!='string'){
            return "";
        }
        if(this.payOftenEditModel.howOftenId&&this.payOftenEditModel.nextPayDay&&this.payOftenEditModel.lastWorkDay){
          return JSON.stringify(this.payOftenEditModel);
        }
        return ""
      },
      payPeriod(){
        return this.$store.getters.payPeriod;
      },
      isCanSubmit() {
        return this.payOftenEditModel.nextPayDay&&this.payOftenEditModel.lastWorkDay&&this.payOftenEditModel.payScheduleName;
      }

    },
    watch:{
      listPayPeriods:function (value) {
       if(!value) return;
        this.$store.dispatch("getPayPeriod",{howOftenId:this.payOftenEditModel.howOftenId,nextPayDay:this.payOftenEditModel.nextPayDay,lastWorkDay:this.payOftenEditModel.lastWorkDay});
      },

    },
    mounted:function(){
    },
    methods:{
      back:function(){
        this.$router.push('/payRoll/payRollCenter');
      },
      getPersonId(){
        return this.$route.params.id;
      },
      clearData:function () {
        this.payOftenEditModel = {
          howOftenId:"",
          nextPayDay:"",
          lastWorkDay:"",
          payScheduleName:""
        },
        this.$store.commit('setCommonStateData',{key:'payPeriod',data:null});
      },
      changeSelectDate(){

      },
      submit(){
        var t = this;
        var param = t.payOftenEditModel;
        t.$store.dispatch("savePaySchedule",param).then(function () {
          t.$message.success('add Success');
          t.$router.back();
        });
      }
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style  rel="stylesheet/scss"  type="text/css" lang="scss" scoped>

  @import "../../assets/css/variable";
  #payOftenEdit{
    >.content{
      padding: 0;
    }
  }
  .pay_often_edit {
    padding: 50px;
    box-sizing: border-box;
    .pay_often_edit_content {
      .left_content{
        >.title{
          font-size: 20px;
          margin-bottom: 30px;
        }
        .question{
          font-size: 16px;
          line-height: 50px;
        }
        .answer{
          line-height: 50px;
        }
        .pay_often_edit_btn_group{
          margin-top: 40px;
        }
      }
      .right_content{
        .pay_date_list{
          min-height: 500px;
          box-shadow: 0 0 11px 4px #ddd;
          position: relative;
          overflow: hidden;
          padding: 20px;
          background: -webkit-linear-gradient(bottom, #fff , $activeColor,#fff); /* Safari 5.1 - 6.0 */
          background: -o-linear-gradient(bottom,#fff , $activeColor,#fff); /* Opera 11.1 - 12.0 */
          background: -moz-linear-gradient(bottom, #fff , $activeColor,#fff); /* Firefox 3.6 - 15 */
          background: linear-gradient(to bottom, #fff , $activeColor,#fff); /* 标准的语法 */
          >.title{
            font-size: 14px;
            margin-bottom: 30px;
            line-height: 30px;
            text-align: center;
          }
          .pay_date_list_content{
            min-height: 300px;
            margin:30px;
            background-color: #fff;
            border: 1px #ebf3f9 solid;
            padding: 20px;
            .pay_date_item{
              line-height: 40px;
              border-bottom: 1px #ddd solid;
              font-size: 12px;
              &.title{
                font-size: 14px;
                font-weight: bold;
              }
            }
          }
          .bottom_circle {
            .circle_item {
              position: absolute;
              bottom: -20px;
              left: -2px;
              width: 70px;
              height: 70px;
              background-color: #fff;
              border-radius: 50%;
              &:first-child {
                bottom: -80px !important;
                left: -20px !important;
                width: 140px;
                height: 140px;
              }
            }
          }
        }
      }
    }

  }
</style>
